/**
 * author      : dormi330
 * date        : 2018/6/24
 * project     : mybatis
 * description : 订单 data access service, 如果有缓存, 则在这一层实现
 */

package org.wzq.learn.domain.order;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.wzq.learn.infrastructure.persist.mybatis.OrderDeliveryMapper;
import org.wzq.learn.infrastructure.persist.mybatis.OrderItemMapper;
import org.wzq.learn.infrastructure.persist.mybatis.OrderSummaryMapper;
import org.wzq.learn.infrastructure.persist.mybatis.TradeOrderMapper;

import java.util.Date;

@Repository
public class OrderRepository {

    @Autowired
    private TradeOrderMapper tradeOrderMapper;

    @Autowired
    private OrderSummaryMapper orderSummaryMapper;

    @Autowired
    private OrderDeliveryMapper orderDeliveryMapper;

    @Autowired
    private OrderItemMapper orderItemMapper;


    public void saveOrderSummary(OrderSummary orderSummary) {
        orderSummaryMapper.insert(orderSummary);
    }

    public void saveTradeOrder(TradeOrder tradeOrder) {
        tradeOrderMapper.insert(tradeOrder);
    }

    public void saveOrderItem(OrderItem orderItem) {
        orderItemMapper.insert(orderItem);
    }

    public void saveOrderDelivery(OrderDelivery orderDelivery) {
        orderDeliveryMapper.insert(orderDelivery);
    }


    public int updateTradeOrderStatus(
            String tenantCode, String tradeOrderId, String fromStatus,
            String toStatus, String rejectReason, Date updatedAt, String updatedBy) {

        return tradeOrderMapper.updateStatus(
                tenantCode, tradeOrderId, fromStatus,
                toStatus, rejectReason, updatedAt, updatedBy);
    }

}
